package com.zhou.util.tag;

import java.util.LinkedHashMap;
import java.util.Map;

public class Select extends Tag {
    private Map<Object,Option> optMap = new LinkedHashMap<>(3);
    public Select() {
        this(true);
    }
    public Select(boolean df) {
        super("select");
        if(df){
            Option o = new Option("请选择","");
            optMap.put("",o);
            append(o);
        }

    }
    public Select(String dn,Object dv) {
        super("select");
        Option o = new Option(dn,dv);
        optMap.put(dv,o);
        append(o);
    }
    public Select add(String n , Object v){
        Option option = optMap.get(v);
        if(option == null){
            option = new Option();
            append(option);
            optMap.put(v,option);
        }
        option.setVal(v).setText(n);
        return this;
    }
    public Select remove(Object v){
        Option op = optMap.remove(v);
        if(op != null){
            body.remove(op);
        }
        //append(option);
        return this;
    }
    public Select select(Object v){
        Option op = optMap.get(v);
        if(op != null){
            op.select();
        }
        //append(option);
        return this;
    }

    public static void main(String[] args) {
        Select select = new Select();
        select.add("哈哈","1");
        select.add("嘿嘿","2");
        System.out.println(select.toString());
        select.add("嘿嘿2","2");
        System.out.println(select.toString());
        select.remove("2");
        System.out.println(select.toString());
    }
}
